package com.rop.znyx.search.api;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.rop.znyx.common.result.Result;
import com.rop.znyx.model.product.SkuInfo;
import com.rop.znyx.model.search.SkuEs;
import com.rop.znyx.search.service.SkuService;
import com.rop.znyx.vo.search.SkuEsQueryVo;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Created with IntelliJ IDEA
 * User: Rop
 * Date: 2023/6/30
 * Time: 17:44
 * Description:
 */

@RestController
@RequestMapping("api/search")
@RequiredArgsConstructor
public class SkuApiController {

    private final SkuService skuService;

    /**
     * 查询分类商品
     */
    @GetMapping("sku/{page}/{limit}")
    public Result<Page<SkuEs>> listSku(@PathVariable("page") Integer page, @PathVariable("limit") Integer limit, SkuEsQueryVo skuEsQueryVo) {
        Pageable pageable = PageRequest.of(page - 1, limit);
        Page<SkuEs> pageModel = skuService.search(pageable, skuEsQueryVo);
        return Result.ok(pageModel);
    }

    /**
     * 上架商品
     */
    @ApiOperation(value = "上架商品")
    @GetMapping("inner/upperSku/{skuId}")
    public Result<Boolean> upperGoods(@PathVariable("skuId") Long skuId) {
        skuService.upperSku(skuId);
        return Result.ok();
    }

    /**
     * 下架商品
     */
    @ApiOperation(value = "下架商品")
    @GetMapping("inner/lowerSku/{skuId}")
    public Result<Boolean> lowerGoods(@PathVariable("skuId") Long skuId) {
        skuService.lowerSku(skuId);
        return Result.ok();
    }

    /**
     * 查询上架商品
     */
    @ApiOperation(value = "查询上架商品")
    @GetMapping("inner/findHotSkuList")
    public Result<List<SkuEs>> findHotSkuList() {
        return Result.ok(skuService.findHotSkuList());
    }

    @ApiOperation(value = "更新商品incrHotScore")
    @GetMapping("inner/incrHotScore/{skuId}")
    public Boolean incrHotScore(@PathVariable("skuId") Long skuId) {
        // 调用服务层
        skuService.incrHotScore(skuId);
        return true;
    }

}
